This section will tell you how to use CAStar. The class is designed to allow it to flexibly adapt to other applications, although the emphasis is on standard tile-based problems. The class uses several function pointers as well as callback data to allow the class to be utilitized in a variety of other ways.
The function pointers are based around this prototype (defined in ASIncludes.h):
typedef int(*_asFunc)(_asNode *, _asNode *, int, void *);
The two function pointers that are used in the A* algorith are udCost and udValid. udCost will validate the cost of the node. CAStar will pass the parent node, the node in question, the data is always 0, and the void pointer is the m_pCBData member variable. udValid follows the same criteria.
m_pCBData is a void pointer that the programmer can set. It can used to pass a this pointer is static member functions are used in C++ classes.
There are a similar pair of function pointers that can notify an application when an A* event occurs. These are udNotifyChild that is triggered when a child is added. The function passes the parent, then the child, a data item that corresponds to the type of child being added (see ASIncludes.h for the meanings of these values) and then the m_pNCData void pointer. udNotifyList occurs when an item is added or removed from the Open or Closed lists. This passes the previous node in the relevant list, the node in question, a data item (see ASIncludes.h again) and the m_pNCData.
As before, m_pNCData is a void pointer that the programmer can use for his own purposes.
See the A* Explorer source code for specifics/examples on how to use CAStar. Functions to look for include:
CAseDoc::AS_Valid
CAseDoc::AS_Cost
CAseDoc::AS_RelativeCost
CAseDoc::SetupAStar
CNodeView::OnNotifyChild
CNodeView::OnNotifyList
Add a user-defined function for the heuristic.
Template the class for use with other data types?
Optimize the algorithm. This was probably require you to remove the notification functions, since they will be a definite source of slow-down.
Hope A* Explorer has helped and feel free to drop me a line at jmatthews@generation5.org for help.
Copyright ©, J.Matthews 2001-2002